package com.example.studentapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.studentapp.R;
import com.example.studentapp.beans.Diary;
import com.example.studentapp.diary.DetailDairyActivity;

import java.util.List;

// 日记详情列表
public class DiaryAdapter extends BaseAdapter {
    Context context;
    List<Diary> list;
    int[] icons = {R.drawable.sun,R.drawable.raining,R.drawable.mostly_cloudy};
    public DiaryAdapter(Context context,List<Diary> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_diary,null);
        TextView item_diary_titleTV = view.findViewById(R.id.item_diary_titleTV);
        item_diary_titleTV.setText(list.get(i).getTitle());
        TextView item_diary_dateTV = view.findViewById(R.id.item_diary_dateTV);
        item_diary_dateTV.setText(list.get(i).getRecordDate());
        ImageView item_diary_moreIV = view.findViewById(R.id.item_diary_moreIV);
        item_diary_moreIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, DetailDairyActivity.class);
                // 传参
                intent.putExtra("id",list.get(i).getId());
                context.startActivity(intent);
            }
        });
        ImageView item_diary_weaIV = view.findViewById(R.id.item_diary_weaIV);
        String weather = list.get(i).getWeather();
        if(weather.equals("晴天")){
            item_diary_weaIV.setImageResource(icons[0]);

        }else if(weather.equals("雨天")){
            item_diary_weaIV.setImageResource(icons[1]);

        }else if(weather.equals("多云")){
            item_diary_weaIV.setImageResource(icons[2]);

        }
        return view;
    }
}
